<%@ page contentType="text/html; charset=UTF-8"%>
<%
//当前页
int currentPage = Integer.parseInt(request.getParameter("currentPage"));
//总记录数
int totalRecord = Integer.parseInt(request.getParameter("totalRecord"));
String formName = request.getParameter("formName");

int pageSize = 10;
String url = request.getParameter("url");
// System.out.println(currentPage);
// System.out.println(totalRecord);
if( null!=request.getParameter("pageSize")){
	pageSize = Integer.parseInt(request.getParameter("pageSize"));
}

int totalPage = 0;
if(totalRecord % pageSize != 0){
	totalPage = totalRecord / pageSize +1;
}else{
	totalPage = totalRecord / pageSize;
}
if(currentPage>totalPage){
	currentPage = totalPage;
}

//计算最小页数
int p = 0 ;
if(currentPage % 5 != 0){
	p = currentPage / 5;
}else{
	p = currentPage / 5-1;
}

out.println("<sapn id='page1'><a href=\"javascript:submitPage(1,'"+formName+"')\" >首页</a>");
if(currentPage>1){
	out.println("<a href=\"javascript:submitPage("+(currentPage-1)+",'"+formName+"')\" >上一页</a>");
}
if(currentPage<=3){
	for(int i=1;i<=p*5+5 && i <= totalPage;i++){
		if(currentPage==i){
			out.println("<b><u>"+i+"</u></b>");	
		}else{
			out.println("<a href=\"javascript:submitPage("+i+",'"+formName+"')\" >"+i+"</a>");
		}
	}
}else{
	for(int i=currentPage-2;i<=currentPage+2 && i <= totalPage;i++){
		if(currentPage==i){
			out.println("<b><u>"+i+"</u></b>");	
		}else{
			out.println("<a href=\"javascript:submitPage("+i+",'"+formName+"')\">"+i+"</a>");
		}
	}
}
if(currentPage<totalPage){
	out.println("<a href=\"javascript:submitPage("+(currentPage+1)+",'"+formName+"')\" >下一页</a>");
}
out.println("<a href=\"javascript:submitPage("+totalPage+",'"+formName+"')\" >末页</a></span>");



// for(int i=p*5+1;i<=p*5+5 && i <= totalPage ;i++){
// 	if(currentPage==i){
// 		out.println(i);	
// 	}else{
// 		out.println("<a href='"+url+"&currentPage="+i+"'>"+i+"</a>");	
// 	}
// }
//隐藏域
//out.println("<input type='hidden' name='currentPage' id='currentPage' value='"+currentPage+"'>");
//javascript
out.println("<span id='page2'>第"+currentPage+"页 转<input type='text' style='width:30px' name='currentPage' id='currentPage' value='"+currentPage+"'>页 <a href=\"javascript:submitPage2('"+formName+"')\">GO</a> 共"+totalRecord+"条;&nbsp共"+totalPage+"页</span>");
%>
<script type="text/javascript">
function submitPage(currPage,formName)
{ 
	document.all.currentPage.value=currPage;
	submitForm=eval("document."+formName);  
	submitForm.submit();
}

function submitPage2(formName){
	var curr =  document.all.currentPage.value;
	var numReg = /^[1-9]+([0-9]*)$/;
	//alert(numReg.test(curr));
	if(!numReg.test(curr)){
		alert("请输入大约零的整数！");
		return;
	}
	
	submitForm=eval("document."+formName);  
	submitForm.submit();
}
</script>